﻿//NETSTANDARD2_0 || NETCOREAPP2_1 || NETCOREAPP2_0
#if NETSD
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;

namespace QW.Core.Web
{
    /// <summary>
    /// 静态上下文构建器
    /// </summary>
    public static class StaticHttpContextBuilder
    {
        /// <summary>
        /// 使用HttpContext
        /// <para>请先注入 services.AddHttpContextAccessor();</para>
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseStaticHttpContext(this IApplicationBuilder app)
        {
            var httpContextAccessor = app.ApplicationServices.GetRequiredService<IHttpContextAccessor>();
            HttpContext.Configure(httpContextAccessor);
            return app;
        }
    }
}
#endif